<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
</head>
<body>
<form action="" method="post" class="row" enctype="multipart/form-data">
    @csrf
    @if ($errors->any())
        <div class="alert alert-danger">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
    <div class="form-group col-md-12">
        <label for="type">一级分类</label>
        <select style="width: 200px" name="" id="one" >
            <option>请选择分类</option>
            @foreach($omit as $val)
                <option id="{{$val->id}}" value="{{$val->id}}">
                    {{$val->shop_type_name}}
                </option>
            @endforeach
        </select>
        &nbsp;
        <label for="type">二级分类</label>
        <select style="width: 200px" name="" id="two" >
            <option>请选择分类</option>
        </select>
        &nbsp;&nbsp;
        <label for="type">三级分类</label>
        <select style="width: 200px" name="" id="three" >
            <option>请选择分类</option>
        </select>
    </div>
    </form>
</body>
</html>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<script src="/ueditor/ueditor.all.js"></script>
<script>
        $("#one").change(function()
        {
            $("#two").empty().append("<option value='0'>请选择</option>");
            let pid=$(this).val();
            console.log(pid);
            $.ajax({
            type: "get",
            url: "{{route('good.second')}}",
            dataType: "json",
            data: {pid: pid},
            success:function(res)
        {
            console.log(res);
            res.forEach(function(v){
            console.log(v);
            console.log(v.shop_type_name);
            $("#two").append("<option value="+v.id+">"+v.shop_type_name+"</option>");
        })
        }
        });
        });
        $("#two").change(function()
        {
            $("#three").empty().append("<option value='0'>请选择</option>");
            let pid =$(this).val();
            console.log(pid);
            $.ajax({
            type: "get",
            url: "{{route('good.third')}}",
            dataType: "json",
            data: {pid: pid},
            success:function(res)
        {
            res.forEach(function(v){
            // console.log(v);
            $("#three").append("<option value="+v.id+">"+v.shop_type_name+"</option>");
        })
        }
        });
        });
</script>


